package com.atguigu.lease.admin.service.impl;

import com.atguigu.lease.model.dto.ViewAppointmentQueryDto;
import com.atguigu.lease.model.vo.AppointmentItemVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.bean.ViewAppointment;
import com.atguigu.lease.admin.service.ViewAppointmentService;
import com.atguigu.lease.admin.mapper.ViewAppointmentMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @author 1
* @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
* @createDate 2025-09-22 17:18:51
*/
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
    implements ViewAppointmentService{

    @Override
    public Page<AppointmentItemVo> getPage(ViewAppointmentQueryDto appointmentQueryDto) {
        QueryWrapper<Object> wrapper = Wrappers.query();
        //  province_id = 1
        wrapper.eq(StringUtils.hasText(appointmentQueryDto.getProvinceId()),
                "t2.province_id", appointmentQueryDto.getProvinceId());
        wrapper.eq(StringUtils.hasText(appointmentQueryDto.getCityId()),
                "t2.city_id", appointmentQueryDto.getCityId());
        wrapper.eq(StringUtils.hasText(appointmentQueryDto.getDistrictId()),
                "t2.district_id", appointmentQueryDto.getDistrictId());
        wrapper.eq(StringUtils.hasText(appointmentQueryDto.getApartmentId()),
                "t1.apartment_id", appointmentQueryDto.getApartmentId());
        wrapper.like(StringUtils.hasText(appointmentQueryDto.getName()) ,
                "t1.name" , appointmentQueryDto.getName());
        wrapper.like(StringUtils.hasText(appointmentQueryDto.getPhone()) ,
                "t1.phone" , appointmentQueryDto.getPhone());
        wrapper.eq("t1.is_deleted" , 0);
        Page<AppointmentItemVo> page = baseMapper.selectAppointmentItemVoPage( new Page<AppointmentItemVo>(appointmentQueryDto.getCurrent(),
                appointmentQueryDto.getSize()) , wrapper);
        return page;
    }
}




